package com.dc.commons.shiro.defaults;

import java.util.Map;

import com.dc.commons.shiro.persistence.Permission;
import com.dc.commons.shiro.service.PermissionService;
import com.dc.commons.status.DataStatus;
import com.dc.commons.status.UseStatus;
import com.dc.commons.sys.persistence.Menu;
import com.dc.commons.sys.persistence.User;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class DefaultPermissionService implements PermissionService{

	private static final Map<String, DefaultUser> users=Maps.newConcurrentMap();
	@SuppressWarnings("unused")
	private static final Map<String,Menu> menus=Maps.newConcurrentMap();
	
	static {
		
		DefaultUser admin=new DefaultUser("管理员","admin");
		admin.setRoles(Lists.newArrayList("admin","agent"));
		admin.setMenus(Lists.newArrayList("*"));
		users.put("admin", admin);
		
		DefaultUser wangjd=new DefaultUser("王建栋","wangjd");
		wangjd.setRoles(Lists.newArrayList("admin","agent"));
		wangjd.setMenus(Lists.newArrayList("user:userAdd","user:userQuery"));
		wangjd.setDataStatus(DataStatus.INVALID);
		users.put("wangjd", wangjd);
		
		
		DefaultUser agent=new DefaultUser("坐席","agent");
		agent.setRoles(Lists.newArrayList("agent"));
		agent.setMenus(Lists.newArrayList("user:userQuery"));
		agent.setUseStatus(UseStatus.DE_ACTIVATE);
		users.put("agent", agent);
	}
	public User findUserByName(String name){
		return users.get(name);
	}
	public Permission findPermissionsByName(String name){
		DefaultUser user=users.get(name);
		Permission permission=new Permission(user.getRoles(),user.getMenus());
		return permission;
	}
	public Menu findMenusByName(String name){
		return null;
	}
}
